package org.linlinjava.litemall.wx.web;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.core.validator.Order;
import org.linlinjava.litemall.core.validator.Sort;
import org.linlinjava.litemall.db.domain.LitemallRecharge;
import org.linlinjava.litemall.db.domain.UserRechargeVo;
import org.linlinjava.litemall.db.service.LitemallRechargeService;
import org.linlinjava.litemall.wx.annotation.LoginUser;
import org.linlinjava.litemall.wx.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/wx/recharge")
@Validated
public class WxRechargeController {
    private final Log logger = LogFactory.getLog(WxRechargeController.class);

    @Autowired
    private LitemallRechargeService rechargeService;
    @Autowired
    UserInfoService userInfoService;

    /**
     * 帮助中心
     */
    @GetMapping("/list")
    public Object list(@LoginUser Integer userId,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer size,
                       @Sort @RequestParam(defaultValue = "add_time") String sort,
                       @Order @RequestParam(defaultValue = "desc") String order) {
        List<LitemallRecharge> rechargeList = rechargeService.querySelective(userId, page, size, sort, order);
        return ResponseUtil.okList(rechargeList);
    }

    /**
     * 帮助中心
     */
    @PostMapping("/recharge")
    public Object recharge(@LoginUser Integer userId,
                           @RequestBody UserRechargeVo userRechargeVo) {
        return userInfoService.recharge(userId, userRechargeVo);
    }

}
